﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CIT.WMS.houseWork.Helper;

namespace CIT.WMS.output
{
    public partial class FrmOutDocPrepare : Form
    {
        #region 变量
        bool flag = false;
        bool result = false;
        bool check_doc = false;
        DataTable dt_doc = new DataTable();
        bool isSMT = false;
        string doc_no = string.Empty;//单据号
        DataTable _dt_ReserchMaterial = new DataTable();//可备料的物料
        string line = string.Empty;//线别
        string wocode = string.Empty;//工单
        string SfcNo = string.Empty;//制令单

        string PCB_Material = string.Empty;//SMT段的PCB料号
        /// <summary>
        /// 是否进入替代料发料模式
        /// </summary>
        bool isReplace = false;
        #endregion
        #region 构造
        public FrmOutDocPrepare()
        {
            InitializeComponent();
            databind();
        }
        #endregion
        #region 绑定发料单
        private void databind()
        {
            string strSql = string.Format(@"SELECT A.S_Doc_NO FROM T_Bllb_StorageDoc_tbsd A WHERE A.S_Doc_Type='7' AND A.Close_Flag='N' AND A.IsAutoCreate='N' ORDER BY A.Create_Time DESC");
            DataTable dt = Utils.NMS.QueryDataTable(Utils.uContext, strSql, new CIT.WMS.MESWcf.CmdParameter[0]);
            DataRow dr = dt.NewRow();
            dr["S_Doc_NO"] = string.Empty;
            dr["S_Doc_NO"] = string.Empty;
            dt.Rows.InsertAt(dr, 0);
            cbo_DocNo.DisplayMember = "S_Doc_NO";
            cbo_DocNo.ValueMember = "S_Doc_NO";
            cbo_DocNo.DataSource = dt;

        }
        #endregion
        #region 输入物料SN
        private void txt_reelid_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                if (txt_reelid.Text.Trim() == string.Empty)
                {
                    lbl_msg.Text = "物料条码不能为空.";
                    lbl_msg.ForeColor = Color.Red;
                    txt_reelid.Text = string.Empty; ;
                    txt_reelid.Focus();
                    return;
                }
                //ClearControl();
                lbl_msg.Text = string.Empty;
                if (!CheckDoc())//校验备料单
                {
                    return;
                }


                //校验物料SN是否在库并且可用
                string strSql = string.Format(@"SELECT Lock_Flag,Enable,MaterialCode,QTY,Storage_SN,DateCode,Version AS Ver FROM dbo.T_Bllb_StockInfo_tbsi WHERE SerialNumber ='{0}'", txt_reelid.Text.Trim());
                DataTable dt_material = Utils.NMS.QueryDataTable(Utils.uContext, strSql, new CIT.WMS.MESWcf.CmdParameter[0]);
                if (dt_material.Rows.Count == 0)
                {
                    lbl_msg.Text = "物料条码不存在.";
                    lbl_msg.ForeColor = Color.Red;
                    txt_reelid.Text = string.Empty; ;
                    txt_reelid.Focus();
                    return;
                }
                string lock_flag = dt_material.Rows[0]["Lock_Flag"].ToString();//状态
                string error_text = string.Empty;
                switch (lock_flag)
                {
                    case "0":
                        break;
                    case "1":
                        error_text = "物料盘点中";
                        break;
                    case "2":
                        error_text = "物料冻结中";
                        break;
                    case "3":
                        error_text = "物料二次送检中";
                        break;
                    case "4":
                        error_text = "物料被报废";
                        break;
                    case "5":
                        error_text = "物料二检NG";
                        break;
                    case "6":
                        error_text = "物料备料中";
                        break;
                    case "7":
                        error_text = "物料已出库";
                        break;
                    case "8":
                        error_text = "物料被合盘";
                        break;
                    case "9":
                        error_text = "物料已出库，并冻结中";
                        break;
                    case "10":
                        error_text = "物料退料中";
                        break;
                    default:
                        error_text = "物料非可备料状态";
                        break;
                }
                if (error_text != string.Empty)
                {
                    lbl_msg.Text = error_text;
                    lbl_msg.ForeColor = Color.Red;
                    txt_reelid.Text = string.Empty; ;
                    txt_reelid.Focus();
                    return;
                }
                bool b_EmptyVer = true;//是否只有一条这个物料
                bool b_Need_ver = false;//是否校验版本
                string str_Need_Ver = string.Empty;//需要的物料版本
                string Ver = string.Empty;
                DataRow[] drs_ver = _dt_ReserchMaterial.Select(string.Format("MaterialCode='{0}'", SqlInput.ChangeNullToString(dt_material.Rows[0]["MaterialCode"])));
                if (drs_ver.Length > 0)
                {
                    foreach (DataRow dr in drs_ver)
                    {
                        if (SqlInput.ChangeNullToString(dr["Ver"]) == string.Empty)//判断是否有这个版本的物料需要发，库存物料都是有版本号
                        {
                            b_EmptyVer = true;
                            break;
                        }
                        else if (SqlInput.ChangeNullToString(dr["Ver"]) == SqlInput.ChangeNullToString(dt_material.Rows[0]["Ver"]))//有相同版本的物料
                        {
                            b_Need_ver = true;
                            Ver = SqlInput.ChangeNullToString(dr["Ver"]);
                        }
                        else//需要的物料版本
                        {
                            str_Need_Ver += "[" + SqlInput.ChangeNullToString(dr["Ver"]) + "]";
                        }
                    }
                }
                if (!b_EmptyVer & !b_Need_ver & str_Need_Ver != string.Empty)//判断物料的版本不是所需要的版本
                {
                    lbl_msg.Text = "备料单中此物料所需的版本为" + str_Need_Ver;
                    lbl_msg.ForeColor = Color.Red;
                    txt_reelid.Text = string.Empty;
                    txt_reelid.Focus();
                    ReserchMateirl();//重新获取可备物料
                    return;
                }
                else if (b_EmptyVer & !b_Need_ver)//存在版本为空的情况，并且当前物料不是所需要的特定版本物料
                {
                    Ver = string.Empty;
                }
                #region 判断datecode不同值数量
                //DataView dataView = _dt_ReserchMaterial.DefaultView;
                //DataTable dataTableDistinct = dataView.ToTable(true, "MaterialCode", "DateCode", "QTY","Ver");
                //string maxDateCode = dataTableDistinct.Compute("max(DateCode)", string.Format(@"MaterialCode='{0}'", SqlInput.ChangeNullToString(dt_material.Rows[0]["MaterialCode"]))).ToString();
                //string minDateCode = dataTableDistinct.Compute("min(DateCode)", string.Format(@"MaterialCode='{0}'", SqlInput.ChangeNullToString(dt_material.Rows[0]["MaterialCode"]))).ToString();

                //string maxQTY = dataTableDistinct.Compute("max(QTY)", string.Format(@"MaterialCode='{0}'", SqlInput.ChangeNullToString(dt_material.Rows[0]["MaterialCode"]))).ToString();
                //string minQTY = dataTableDistinct.Compute("min(QTY)", string.Format(@"MaterialCode='{0}'", SqlInput.ChangeNullToString(dt_material.Rows[0]["MaterialCode"]))).ToString();

                //DataRow[] drs_Distinct = dataTableDistinct.Select(string.Format(@"MaterialCode='{0}'", SqlInput.ChangeNullToString(dt_material.Rows[0]["MaterialCode"])));
                //int distinct_length = drs_Distinct.Length;

                //DataRow[] drs = _dt_ReserchMaterial.Select(string.Format(@"SerialNumber='{0}'", txt_reelid.Text.Trim()));


                DataView dataView = _dt_ReserchMaterial.DefaultView;
                DataTable dataTableDistinct = dataView.ToTable(true, "MaterialCode", "DateCode", "QTY", "Ver");
                string maxDateCode = dataTableDistinct.Compute("max(DateCode)", string.Format(@"MaterialCode='{0}' and Ver='{1}'", SqlInput.ChangeNullToString(dt_material.Rows[0]["MaterialCode"]), Ver)).ToString();
                string minDateCode = dataTableDistinct.Compute("min(DateCode)", string.Format(@"MaterialCode='{0}' and Ver='{1}'", SqlInput.ChangeNullToString(dt_material.Rows[0]["MaterialCode"]), Ver)).ToString();

                string maxQTY = dataTableDistinct.Compute("max(QTY)", string.Format(@"MaterialCode='{0}' and Ver='{1}'", SqlInput.ChangeNullToString(dt_material.Rows[0]["MaterialCode"]), Ver)).ToString();
                string minQTY = dataTableDistinct.Compute("min(QTY)", string.Format(@"MaterialCode='{0}' and Ver='{1}'", SqlInput.ChangeNullToString(dt_material.Rows[0]["MaterialCode"]), Ver)).ToString();

                DataRow[] drs_Distinct = dataTableDistinct.Select(string.Format(@"MaterialCode='{0}' and Ver='{1}'", SqlInput.ChangeNullToString(dt_material.Rows[0]["MaterialCode"]), Ver));
                int distinct_length = drs_Distinct.Length;

                DataRow[] drs = _dt_ReserchMaterial.Select(string.Format(@"SerialNumber='{0}'", txt_reelid.Text.Trim()));


                if (SqlInput.ChangeNullToInt(dt_material.Rows[0]["DateCode"], 0) != SqlInput.ChangeNullToInt(minDateCode, 0))//物料SN不在范围中，判断datecode和数量是否与备选的物料一致
                {
                    //lbl_msg.Text = "不符合DataCode优先";
                    lbl_msg.Text = SqlInput.ChangeNullToInt(dt_material.Rows[0]["DateCode"], 0) + "不符合DataCode优先，请选择DataCode为" + SqlInput.ChangeNullToInt(minDateCode, 0) + "物料";
                    lbl_msg.ForeColor = Color.Red;
                    return;
                }
                else if (maxQTY != minQTY)//判断是否所选的料盘中最小料盘和最大料盘是否一致，若不是，则先发最小料盘
                {
                    if (dt_material.Rows[0]["QTY"].ToString() == maxQTY)//若有尾盘，并且扫描的不是尾盘则提示
                    {
                        lbl_msg.Text = "不符合尾盘优先";
                        lbl_msg.ForeColor = Color.Red;
                        return;
                    }
                }


                #endregion

                //string doc_no = cbo_sfcNo.SelectedValue.ToString();//备料单
                string MaterialCode = dt_material.Rows[0]["MaterialCode"].ToString();//料号
                int qty = SqlInput.ChangeNullToInt(dt_material.Rows[0]["QTY"], 0);//数量         

                strSql = string.Empty;
                string TBDS_ID = string.Empty;
                string strSql_Sum = string.Empty;//SQL汇总


                strSql = string.Format(@"SELECT Plan_Qty,QTY,TSDM_ID FROM dbo.T_Bllb_StorageDocMaterial_tsdm WHERE S_Doc_NO='{0}' AND MaterialCode='{1}' AND Ver='{2}'", doc_no, MaterialCode,Ver);
                DataTable dt = Utils.NMS.QueryDataTable(Utils.uContext, strSql, new CIT.WMS.MESWcf.CmdParameter[0]);
                if (dt.Rows.Count == 0)
                {
                    if (Ver == string.Empty)
                        lbl_msg.Text = "备料单中不存在物料" + dt_material.Rows[0]["MaterialCode"].ToString();
                    else
                    {
                        lbl_msg.Text = "备料单中不存在版本为" + Ver + "物料" + dt_material.Rows[0]["MaterialCode"].ToString();
                    }
                    lbl_msg.ForeColor = Color.Red;
                    txt_reelid.Text = string.Empty; ;
                    txt_reelid.Focus();
                    return;
                }
                DataRow[] drs_qty = dt.Select("Plan_Qty>QTY");//是否此物料已备齐

                if (drs_qty.Length == 0)//备料数量是否已达到
                {
                    lbl_msg.Text = "备料单中物料" + dt_material.Rows[0]["MaterialCode"].ToString() + "已备齐";
                    lbl_msg.ForeColor = Color.Red;
                    txt_reelid.Text = string.Empty; ;
                    txt_reelid.Focus();
                    return;
                }


                #region 单据处理
                strSql = string.Format(@"SELECT RowNumber,TSDM_ID FROM T_Bllb_StorageDocMaterial_tsdm WHERE S_DOC_NO='{0}' AND MATERIALCODE='{1}'  AND Plan_Qty>QTY AND VER='{2}' ORDER BY RowNumber ASC", doc_no, MaterialCode,Ver);
                DataTable dt_RowNumber = Utils.NMS.QueryDataTable(Utils.uContext, strSql, new CIT.WMS.MESWcf.CmdParameter[0]);
                if (dt_RowNumber.Rows.Count > 0)
                {
                    int rownumber = SqlInput.ChangeNullToInt(dt_RowNumber.Rows[0][0], 0);
                    if (rownumber != 0)
                        strSql_Sum += string.Format(@" UPDATE T_Bllb_StorageDocMaterial_tsdm SET QTY=QTY+{2} WHERE S_Doc_NO='{0}' AND RowNumber='{1}' AND MATERIALCODE='{3}'", doc_no, rownumber, qty, MaterialCode);
                    else
                        strSql_Sum += string.Format(@" UPDATE T_Bllb_StorageDocMaterial_tsdm SET QTY=QTY+{2} WHERE S_Doc_NO='{0}' AND MATERIALCODE='{1}'", doc_no, MaterialCode, qty);
                }  

                //strSql_Sum += string.Format(@" UPDATE T_Bllb_StorageDocMaterial_tsdm SET QTY=QTY+{2} WHERE S_Doc_NO='{0}' AND MaterialCode='{1}'", doc_no, MaterialCode, qty);
                strSql_Sum += string.Format(@" INSERT INTO dbo.T_Bllb_StorageDocDetail_tbsdd
                                                ( S_Doc_NO ,
                                                  MaterialCode ,
                                                  QTY ,
                                                  Create_Time ,
                                                  Creator ,
                                                  SerialNumber,TBDS_ID ,TSDM_ID
                                                )
                                        VALUES  ( '{0}' , -- S_Doc_NO - nvarchar(50)
                                                  '{1}' , -- MaterialCode - nvarchar(50)
                                                  {2} , -- QTY - int
                                                  GETDATE() , -- Create_Time - datetime
                                                  '{3}' , -- Creator - nvarchar(50)
                                                  '{4}',  -- SerialNumber - nvarchar(50)     
                                                  '{5}' ,'{6}'                                              
                                                )", doc_no, MaterialCode, qty, Utils.uContext.UserIDk__BackingField, txt_reelid.Text.Trim(), TBDS_ID,SqlInput.ChangeNullToString(dt.Rows[0]["TSDM_ID"]));
                //修改物料状态
                //strSql_Sum += string.Format(@" UPDATE dbo.T_Bllb_StockInfo_tbsi SET  Lock_Flag='6' WHERE SerialNumber='{0}'", txt_reelid.Text.Trim());
                strSql_Sum += string.Format(@" UPDATE dbo.T_Bllb_StockInfo_tbsi SET Area_SN='', Lock_Flag='6',Location_SN='',TBS_ID='',SfcNo='{1}' WHERE SerialNumber='{0}'", txt_reelid.Text.Trim(), SfcNo);
                //物料操作日志
                strSql_Sum += string.Format(@" INSERT INTO T_Bllb_MaterialLog_tbml(SerialNumber,CreateTime,OperateType,MaterialCode,QTY,Creator,Memo,SfcNo,PLCode)
VALUES('{0}',GETDATE(),'{1}','{2}','{3}','{4}','{5}','{6}','{7}')", txt_reelid.Text.Trim(), "单据备料", MaterialCode, qty, Utils.uContext.UserIDk__BackingField, "", SfcNo, line);
                Utils.NMS.Exectransql(Utils.uContext, strSql_Sum, new CIT.WMS.MESWcf.CmdParameter[0], out flag, out result);
                lbl_msg.Text = "备料成功";
                lbl_msg.ForeColor = Color.Green;
                lbl_LocationSN.Text = doc_no;
                ReserchMateirl();
                txt_reelid.Text = string.Empty; ;
                txt_reelid.Focus();
                #endregion

            }
        }
        #endregion
        #region 制令单变化时初始化显示信息
        private void cbo_DocNo_SelectedIndexChanged(object sender, EventArgs e)
        {
            ClearControl();
        }
        #endregion
        #region 清空控件
        private void ClearControl()
        {
            lbl_MaterialCode.Text = string.Empty;
            lbl_NextSerialNumber.Text = string.Empty;
            lbl_LocationSN.Text = string.Empty;
            lbl_msg.Text = string.Empty;
        }
        #endregion
        #region 校验单据
        private void cbo_DocNo_LostFocus(object sender, EventArgs e)
        {
            if (CheckDoc())
            {

                lbl_msg.Text = "单据设置OK";
                lbl_msg.ForeColor = Color.Green;
                return;
            }
        }
        #endregion
        #region  校验备料单
        /// <summary>
        /// 校验备料单
        /// </summary>
        /// <returns></returns>
        private bool CheckDoc()
        {
            if (cbo_DocNo.SelectedValue == null)
            {
                return false;
            }
            if (cbo_DocNo.SelectedValue.ToString() == string.Empty)
            {
                lbl_msg.Text = "发料单不能为空";
                lbl_msg.ForeColor = Color.Red;
                return false;
            }
            string strSql = string.Format(@"SELECT A.S_Doc_NO,A.SfcNo,A.Close_Flag,B.WoCode,B.PCB_Material,B.BoradCnt,B.Product,B.Line,B.BoardSide,B.planqty FROM T_Bllb_StorageDoc_tbsd A 
LEFT JOIN dbo.SfcDatProduct B ON A.Before_Doc_No=B.SfcNo
WHERE A.S_Doc_NO='{0}' AND  A.S_Doc_Type='7'", cbo_DocNo.Text.Trim());
            dt_doc = Utils.NMS.QueryDataTable(Utils.uContext, strSql, new CIT.WMS.MESWcf.CmdParameter[0]);
            if (dt_doc.Rows.Count == 0)
            {
                lbl_msg.Text = "发料单不存在";
                lbl_msg.ForeColor = Color.Red;
                return false;
            }
            else if (SqlInput.ChangeNullToString(dt_doc.Rows[0]["Close_Flag"]) == "Y")                                              
            {
                lbl_msg.Text = "单据已关闭";
                lbl_msg.ForeColor = Color.Red;
                databind();
                return false;
            }
            wocode = SqlInput.ChangeNullToString(dt_doc.Rows[0]["WoCode"]);//工单

            line = SqlInput.ChangeNullToString(dt_doc.Rows[0]["Line"]);//线别
            PCB_Material = SqlInput.ChangeNullToString(dt_doc.Rows[0]["PCB_Material"]);//PCB料号
            SfcNo = SqlInput.ChangeNullToString(dt_doc.Rows[0]["SfcNo"]);//制令单
            string product = SqlInput.ChangeNullToString(dt_doc.Rows[0]["Product"]);//产品代码
            string BoardSide = SqlInput.ChangeNullToString(dt_doc.Rows[0]["BoardSide"]);//面别
            string ver = string.Empty;//版本
            int BoradCnt = SqlInput.ChangeNullToInt(dt_doc.Rows[0]["BoradCnt"], 1);//拼版数
            int planqty = SqlInput.ChangeNullToInt(dt_doc.Rows[0]["planqty"], 1);//计划数
            if (line.ToUpper().Contains("SMT"))//判断是否为SMT发料
            {            
                isSMT = true;
                //strSql = string.Format(@"select top 1 ver from mdcdatSlot WHERE Line='{0}' AND Product='{1}' AND BoardSide='{2}' order by ver DESC", line, product, BoardSide);
                //DataTable dt_ver = Utils.NMS.QueryDataTable(Utils.uContext, strSql, new CIT.WMS.MESWcf.CmdParameter[0]);
                //if (dt_ver.Rows.Count == 0)
                //{
                //    lbl_msg.Text = "产品" + product + "在线别" + line + "未维护" + BoardSide + "料站表";
                //    lbl_msg.ForeColor = Color.Red;
                //    return false;
                //}
                //else
                //{
                //    ver = SqlInput.ChangeNullToString(dt_ver.Rows[0]["ver"]);//版本
                //    if (ver == string.Empty)
                //    {
                //        ver = "0";
                //    }
                //}
            }
            else
            {
                isSMT = false;
            }
            doc_no = cbo_DocNo.SelectedValue.ToString();
            return ReserchMateirl();//搜索可备料的物料SN
        }
        #endregion
        #region 获取可备料的物料SN
        /// <summary>
        /// 获取可备料的物料SN
        /// </summary>
        private bool ReserchMateirl()
        {
            string strSql = string.Format(@" SELECT COUNT(1) AS SUM_QTY,B.MaterialCode,B.VER FROM dbo.T_Bllb_StorageDoc_tbsd A LEFT JOIN dbo.T_Bllb_StorageDocMaterial_tsdm B ON A.S_Doc_NO=B.S_Doc_NO
WHERE A.S_Doc_NO='{0}' AND B.QTY<B.Plan_Qty GROUP BY B.MaterialCode,B.VER", doc_no);
                DataTable dt_BOM = Utils.NMS.QueryDataTable(Utils.uContext, strSql, new CIT.WMS.MESWcf.CmdParameter[0]);
                if (dt_BOM.Rows.Count == 0)
                {
                    ClearControl();
                    strSql = string.Format(@"UPDATE T_Bllb_StorageDoc_tbsd SET Close_Flag='Y' WHERE S_Doc_NO='{0}'", doc_no);
                    Utils.NMS.Exectransql(Utils.uContext, strSql, new CIT.WMS.MESWcf.CmdParameter[0], out flag, out result);
                    lbl_msg.Text = "单据备料完成";
                    lbl_msg.ForeColor = Color.Green;
                    return false;
                }
                strSql = string.Empty;
  
                string strUnion = string.Empty;
                string ver = string.Empty;
                int M_Count = 1;
                foreach (DataRow dr_bom in dt_BOM.Rows)
                {
                    M_Count = SqlInput.ChangeNullToInt(dr_bom["SUM_QTY"], 0);//相同版本相同物料数量
                    ver = SqlInput.ChangeNullToString(dr_bom["Ver"]).Trim();//物料版本
                    //获取库存中允许发送的物料SN
                    //在库位上的物料才能发料
                    if (strSql != string.Empty)
                    {
                        strUnion = " UNION ";
                    }
                    if (ver == string.Empty)
                    {
                        strSql += strUnion + string.Format(@" SELECT TOP {1} A.SerialNumber,A.Location_SN,A.Area_SN,A.DateCode,A.MaterialCode,A.QTY,'' AS Ver FROM dbo.T_Bllb_StockInfo_tbsi A INNER JOIN dbo.T_Bllb_StorageLocation_tbsl B ON A.Location_SN=B.Location_SN WHERE A.MaterialCode='{0}' AND A.Lock_Flag='0'  ORDER BY A.DateCode ASC,A.QTY ASC,A.Location_SN ASC
", dr_bom["MaterialCode"], M_Count );
                    }
                    else
                    {
                        strSql += strUnion + string.Format(@" SELECT TOP {1} A.SerialNumber,A.Location_SN,A.Area_SN,A.DateCode,A.MaterialCode,A.QTY,A.Version AS Ver FROM dbo.T_Bllb_StockInfo_tbsi A INNER JOIN dbo.T_Bllb_StorageLocation_tbsl B ON A.Location_SN=B.Location_SN WHERE A.MaterialCode='{0}' AND Version='{2}' AND A.Lock_Flag='0'  ORDER BY A.DateCode ASC,A.QTY ASC,A.Location_SN ASC
", dr_bom["MaterialCode"], M_Count, ver);
                    }
                }
                if (string.IsNullOrEmpty(strSql))
                {
                    string msg = string.Empty;
                    foreach (DataRow dr in dt_BOM.Rows)
                    {
                        //msg += dr["MATERIALCODE"].ToString() + Environment.NewLine;
                        msg += dr["MATERIALCODE"].ToString() + (SqlInput.ChangeNullToString(dr["Ver"]) != string.Empty ? "*" + SqlInput.ChangeNullToString(dr["Ver"]) : "" + Environment.NewLine);
                    }

                    lbl_msg.Text = "库存中物料不足" + Environment.NewLine + msg;
                    lbl_msg.ForeColor = Color.Red;
                    return false;
                }
                strSql = " SELECT * FROM (" + strSql + ") M ORDER BY DateCode ASC,QTY ASC ";
                _dt_ReserchMaterial = Utils.NMS.QueryDataTable(Utils.uContext, strSql, new CIT.WMS.MESWcf.CmdParameter[0]);//获取可选备料的物料
                if (_dt_ReserchMaterial.Rows.Count == 0)
                {
                    string msg = string.Empty;
                    foreach (DataRow dr in dt_BOM.Rows)
                    {
                        //msg += dr["MATERIALCODE"].ToString() + Environment.NewLine;
                        msg += dr["MATERIALCODE"].ToString() + (SqlInput.ChangeNullToString(dr["Ver"]) != string.Empty ? "*" + SqlInput.ChangeNullToString(dr["Ver"]) : "" + Environment.NewLine);
                    }

                    lbl_msg.Text = "库存中物料不足" + Environment.NewLine + msg;
                    lbl_msg.ForeColor = Color.Red;
                    return false;
                }               
            lbl_NextSerialNumber.Text =  SqlInput.ChangeNullToString(_dt_ReserchMaterial.Rows[0]["SerialNumber"]);//物料SN
            lbl_MaterialCode.Text = SqlInput.ChangeNullToString(_dt_ReserchMaterial.Rows[0]["MaterialCode"]);//料号
            lbl_LocationSN.Text = SqlInput.ChangeNullToString(_dt_ReserchMaterial.Rows[0]["Location_SN"]);//库位
            return true;
        }


        #endregion

    }
}